package javapop.framework.parser;

import java.util.HashSet;
import java.util.Set;

public class CharNSet extends Char {
	private Set<Character> charset;
	
	public CharNSet(Character...chars) {
		if(chars.length==0)
			throw new IllegalArgumentException("At least one character expected");
		charset = new HashSet<Character>(chars.length);
		for(Character ch : chars) {
			charset.add(ch);
		}
		
		StringBuilder buf = new StringBuilder();
		buf.append("character in { ");
		for(Character ch : charset) {
			buf.append("'");
			buf.append(ch);
			buf.append("' ");
		}
		buf.append("}");
		description = buf.toString();
	}
		
	@Override
	public int hashCode() {
		return description.hashCode();
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj==null) return false;
		if(obj==this) return true;
		if(obj.getClass()!=this.getClass())
			return false;
		return ((CharNSet) obj).charset.equals(charset);
	}

	@Override
	public boolean acceptChar(Character ch) {
		return !charset.contains(ch);
	}

}
